package priv.conceit.study.book.multithread.chapter8.threadpool;

/**
 * study 任务队列的拒绝策略
 *
 * @author Conceit
 * 8/3/2022 增加方法
 * @since 1.0.0, 8/3/2022
 */
@FunctionalInterface
public interface DenyPolicy {


	void reject(Runnable runnable,ThreadPool threadPool);

	/**
	 * 放弃任务
	 */
	class abandon implements DenyPolicy{

		@Override
		public void reject(Runnable runnable,ThreadPool threadPool){

		}
	}

	/**
	 * 抛出异常
	 */
	class throwException implements DenyPolicy{
		@Override
		public void reject(Runnable runnable,ThreadPool threadPool){
			throw new RunnableDenyException("抛出异常 拒绝执行！");
		}
	}

	/**
	 * 直接在调用者的线程中执行
	 */
	class runner implements DenyPolicy{
		@Override
		public void reject(Runnable runnable,ThreadPool threadPool){
			if(!threadPool.isShutdown()){
				runnable.run();
			}
		}
	}





}
